<?php

/**
 *  合同mo'ban 
 * Created by PhpStorm.
 * User: Apache
 * Date: 2019/10/27
 * Time: 10:02
 */
namespace app\api\controller\followmanage;

use app\api\controller\common\ApiBase;
use PhpOffice\PhpWord\TemplateProcessor;
use app\api\controller\common\CommonPlus;

class Contractmodown extends ApiBase
{

    protected $admin;
    protected $model = null;
    public function _initialize()
    {
        $this->admin = session('admin');
    }

    /**
     * 合同管理列表页
     * 模糊查询需后补 暂时先做普版
     */
    public function contractmobanList()
    {
        $keyword = $this->request->param('keyword');
        $template_type = $this->request->param('template_type');
        $project = $this->request->param('project');
        $page = $this->request->param('page');
        $where = array();
        $page = max(1, intval($page));
        $pagesize = 10;
        $where['a.is_delete'] = 0;

        if (!empty($keyword)) {
            $where['a.title'] = array('like', '%' . $keyword . '%');
        }
        if (!empty($template_type)) {
            $where['a.template_type'] = $template_type;
        }
        if (!empty($project)) {
            $where['a.project'] = $project;
        }

        $list =  db('contract_mould_yc')
                ->alias('a')
                ->field('a.id,a.title,a.value,a.template_type,a.project,a.create_time,e.title as e_title,t.contract_name')
                ->join('exhibition e','a.project=e.id','left')
                ->join('contract_type t','a.template_type=t.id','left')
                ->where($where)
                ->limit(($page-1)*$pagesize.','.$pagesize)
                ->order('a.id desc')
                ->select();
         $total = db('contract_mould_yc')
                ->alias('a')
                ->field('a.id,a.title,a.value,a.template_type,a.project,e.title,t.contract_name')
                ->join('exhibition e','a.project=e.id','left')
                ->join('contract_type t','a.template_type=t.id','left')
                ->where($where)
                ->count();
        return json(['code' => 1, 'msg' => 'success', 'data' => ['list' => $list?$list:array(), 'total' => $total]]);
    }
}
